package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import com.msstudio.midlets.MSCMIDlet;
import java.util.Vector;
import javax.microedition.lcdui.*;

public class BlackList
    implements CommandListener
{

    protected Command cmdYes;
    protected Command cmdNo;
    protected Command cmdBack;
    public static final int C_BlackNum = 10;
    public static final int C_BlackItems = 1;
    private List list;
    private long aBlack[];
    private int iBlackNum;
    private boolean iChanged;
    public Vector vList;

    public BlackList()
    {
        cmdYes = null;
        cmdNo = null;
        cmdBack = null;
        list = null;
        aBlack = new long[10];
        iBlackNum = 0;
        iChanged = false;
        vList = new Vector();
    }

    public void loadList()
    {
        iBlackNum = 0;
        PkgTools.getBlackList(this);
        for(int i = 0; i < vList.size() / 1; i++)
            try
            {
                aBlack[iBlackNum] = Long.parseLong((String)vList.elementAt(i * 1));
                iBlackNum++;
            }
            catch(NumberFormatException numberformatexception) { }

    }

    public boolean inBlackList(long l)
    {
        for(int i = 0; i < iBlackNum; i++)
            if(aBlack[i] == l)
                return true;

        return false;
    }

    public void addToBlack(String s, String s1)
    {
        if(vList.size() == 10)
        {
            MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.sUrBLFull, MSCMIDlet.mainForm.GetWindow());
            return;
        }
        vList.addElement(s);
        try
        {
            aBlack[iBlackNum] = Long.parseLong(s);
            iBlackNum++;
        }
        catch(NumberFormatException numberformatexception) { }
        MSCMIDlet.mainMenu.deleteFriend(s);
        MSCMIDlet.friendList.buildFriendList();
        MSCMIDlet.mainForm.show();
        PkgTools.setOtherInfo(null, null, this);
    }

    public String getDBItem(int i)
    {
        if(i >= vList.size())
            return "0";
        else
            return (String)vList.elementAt(i);
    }

    public void show()
    {
        iChanged = false;
        cmdBack = new Command(MSCMIDlet.multiLang.sBack, 2, 2);
        list = new List(MSCMIDlet.multiLang.sBlackList, 3);
        list.addCommand(cmdBack);
        list.setCommandListener(this);
        for(int i = 0; i < vList.size() / 1; i++)
            list.append((String)vList.elementAt(i * 1), null);

        MSCMIDlet.display.setCurrent(list);
    }

    public void commandAction(Command command, Displayable displayable)
    {
        if(command == List.SELECT_COMMAND)
        {
            int i = list.getSelectedIndex();
            cmdYes = new Command(MSCMIDlet.multiLang.sYes, 1, 1);
            cmdNo = new Command(MSCMIDlet.multiLang.sBack, 2, 1);
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.GetCombineMsg(129, "" + aBlack[i]), this, cmdYes, cmdNo);
            return;
        }
        if(command == cmdYes)
        {
            int j = list.getSelectedIndex();
            String s = (String)vList.elementAt(1 * j);
            deleteFromList(j);
            list.delete(j);
            MSCMIDlet.display.setCurrent(list);
            if(!MSCMIDlet.friendList.existFriend(s))
                MSCMIDlet.addFriend.show(list, s);
            return;
        }
        if(command == cmdNo)
        {
            MSCMIDlet.display.setCurrent(list);
            return;
        }
        try
        {
            if(command == cmdBack)
            {
                list = null;
                MSCMIDlet.mainForm.show();
                if(iChanged)
                {
                    MSCMIDlet.friendList.buildFriendList();
                    PkgTools.setOtherInfo(null, null, this);
                }
                return;
            }
        }
        catch(Exception exception) { }
        return;
    }

    public boolean deleteFromBlackList(long l)
    {
        for(int i = 0; i < iBlackNum; i++)
            if(aBlack[i] == l)
            {
                deleteFromList(i);
                if(iChanged)
                {
                    MSCMIDlet.friendList.buildFriendList();
                    PkgTools.setOtherInfo(null, null, this);
                }
                return true;
            }

        return false;
    }

    private void deleteFromList(int i)
    {
        for(int j = 0; j < 1; j++)
            vList.removeElementAt(1 * i + j);

        for(int k = i; k < iBlackNum - 1; k++)
            aBlack[k] = aBlack[k + 1];

        iBlackNum--;
        iChanged = true;
    }
}
